using System.IO;

namespace ThingsGateway.Foundation.Rpc.TouchRpc
{
    /// <summary>
    /// 远程文件系统信息
    /// </summary>
    public abstract class RemoteFileSystemInfo : PackageBase
    {
        /// <summary>
        /// 目录或文件的名称。
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 目录或文件的完整目录。
        /// </summary>
        public string FullName { get; set; }

        /// <summary>
        /// 上次写入当前文件或目录的时间
        /// </summary>
        public DateTime LastWriteTime { get; set; }

        /// <summary>
        /// 上次访问当前文件或目录的时间
        /// </summary>
        public DateTime LastAccessTime { get; set; }

        /// <summary>
        /// 当前文件或目录的创建时间
        /// </summary>
        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 当前文件或目录的特性
        /// </summary>
        public FileAttributes Attributes { get; set; }

        /// <inheritdoc/>
        public override void Package(ByteBlock byteBlock)
        {
            byteBlock.Write(LastWriteTime);
            byteBlock.Write(LastAccessTime);
            byteBlock.Write(CreationTime);
            byteBlock.Write((int)Attributes);
            byteBlock.Write(FullName);
            byteBlock.Write(Name);
        }

        /// <inheritdoc/>
        public override void Unpackage(ByteBlock byteBlock)
        {
            LastWriteTime = byteBlock.ReadDateTime();
            LastAccessTime = byteBlock.ReadDateTime();
            CreationTime = byteBlock.ReadDateTime();
            Attributes = (FileAttributes)byteBlock.ReadInt32();
            FullName = byteBlock.ReadString();
            Name = byteBlock.ReadString();
        }
    }
}